package com.shd.edanpei.ui.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.base.BaseQuickImageAdapter;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.bean.CompanyInfoModel;
import com.shd.edanpei.presenter.contract.CompanyInfoContract;
import com.shd.edanpei.presenter.CompanyInfoPresenter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2018/10/10.
 * 企业信息
 */

public class CompanyInfoActivity extends BaseActivity<CompanyInfoPresenter>
        implements CompanyInfoContract.CompanyInfoIView {

    @BindView(R.id.headline)
    TextView headline;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private Adapter mAdapter;
    private Bundle bundle = new Bundle();

    @Override
    protected int setLayout() {
        return R.layout.activity_companyinfo;
    }

    @Override
    protected CompanyInfoPresenter bindPresenter() {
        return new CompanyInfoPresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        headline.setText("企业信息");
        mAdapter = new Adapter(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(mAdapter);
        mPresenter.getData();
    }

    @Override
    protected void initListener() {
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CompanyInfoModel item = mAdapter.getItem(position);
                if (item.isCanClick()) {
                    bundle.clear();
                    bundle.putStringArrayList(com.shd.edanpei.photo.PhotoViewActivity.PHOTO_LIST, item.getUrl());
                    startActivity(com.shd.edanpei.photo.PhotoViewActivity.class, bundle);
                }
            }
        });
    }

    @OnClick(R.id.iv_headline_back)
    void close() {
        finish();
    }

    @Override
    public void setData(List<CompanyInfoModel> list) {
        mAdapter.setNewData(list);
    }

    class Adapter extends BaseQuickImageAdapter<CompanyInfoModel> {

        public Adapter(Context context) {
            super(context, R.layout.item_company_info);
        }

        @Override
        protected void convert(BaseViewHolder helper, CompanyInfoModel item) {
            helper.setText(R.id.tv_name, item.getName())
                    .setText(R.id.tv_info, item.getInfo());

            if (item.isCanClick()) {
                ((TextView) helper.getView(R.id.tv_info)).setTextColor(getResources().getColor(R.color.main_color));
            }
        }

    }
}
